package com.yzf.enterprise.framework.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.TimeZone;


/**
 * 程序注解配置
 */
@Configuration
@EnableAspectJAutoProxy(exposeProxy = true)// 表示通过aop框架暴露该代理对象,AopContext能够访问
public class ApplicationConfig {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
        return jacksonObjectMapperBuilder -> {
            jacksonObjectMapperBuilder
                    .timeZone(TimeZone.getDefault()) //时区配置
                    .deserializerByType(String.class, new StdScalarDeserializer<String>(String.class) {
                        public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
                            return StringUtils.trimWhitespace(p.getValueAsString()); //trim
                        }
                    });
        };

    }
}
